package com.example.blogapi.service.impl;

import com.alibaba.fastjson.JSON;
import com.example.blogapi.domain.MsSysUser;
import com.example.blogapi.service.TokenService;
import com.example.blogapi.utils.JWTUtils;
import com.mysql.cj.util.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;
@Service
public class TokenServiceImpl implements TokenService {
    @Autowired
    HashMap<String,String> fakeRedis;

    @Override
    public MsSysUser checkout(String token) {
        if (StringUtils.isNullOrEmpty(token)){
            return null;
        }
        Map<String, Object> userMap = JWTUtils.checkToken(token);
        if (userMap==null){
            return null;
        }
        String userJson = fakeRedis.get("TOKEN_"+token);
        if (StringUtils.isNullOrEmpty(userJson)){
            return null;
        }
        MsSysUser user = JSON.parseObject(userJson,MsSysUser.class);
        return user;
    }


}
